/*
 *  Copyright 2013 National Institute of Advanced Industrial Science and Technology
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.sss.mapreduce;

import java.io.Closeable;
import java.util.List;

import org.sss.mapreduce.datatype.Packable;

/**
 * <code>SideData</code> represents an extra data set
 * <p>
 * SSS client programs could use <code>SideData</code> if its <tt>map</tt>/<tt>reduce</tt>
 * method(s) need to access an extra data set beside normal input tuples.
 */
public interface SideData<K extends Packable, V extends Packable> extends Closeable {
  /**
   * Indicates whether this <code>SideData</code> contains a mapping for
   * the specified key.
   *
   * @param  key  the key whose presence in this <code>SideData</code> is to be tested
   * @return <tt>true</tt> if a variable with the specified key exists;
   * <tt>false</tt> otherwise
   */
  public boolean containsKey(K key);
  /**
   * Returns a list of values to which the specified key is mapped, or
   * <tt>null</tt> if <code>SideData</code> contains no mapping for the key.
   *
   * @param  key  the key whose associated values are to be returned
   * @return a list of values to which the specified key is mapped, or
   * <tt>null</tt> if <code>SideData</code> contains no mapping for the key.
   */
  public List<V> get(K key) throws Exception;

  /**
   * Returns iterable to access all keys.
   *
   * @return Iterable to access all keys.
   */
  Iterable<K> keys() throws SssException;

  /**
   * Returns iterable to access all tuples.
   *
   * @return Iterable to access all tuples.
   */
  Iterable<Tuple<K, V>> tuples() throws SssException;
}
